<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
if($_RQ['op']=='main'){
	$avatar=pdo_getcolumn('core_members',array('id'=>$return['item']['mid']),'avatar');
	$return['params']=array('daytype'=>0);
	$return['orderparams']=array('daytype'=>0);
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$return['params']=array();
	//创建时间
	if($_RQ['tstart'] && $_RQ['tend']){
		$params['onlinetime between']=array($_RQ['tstart'],$_RQ['tend']);
	}else{
		$daytype=intval($_RQ['daytype']);
		if($daytype==0){
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['onlinetime']=0;
		}elseif($daytype==1){
			$yesdaytime = mktime(0,0,0,date('m'),date('d')-1,date('Y'));
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['onlinetime between']=array($yesdaytime,$daytime);
		}elseif($daytype=2){
			$day7time = mktime(0,0,0,date('m'),date('d')-7,date('Y'));
			$params['onlinetime >']=$day7time;
		}elseif($daytype==3){
			$monthtime = strtotime(date('Y-m',time()));
			$params['onlinetime >']=$monthtime;
		}elseif($daytype==4){
			$monthtime=strtotime(date('Y-m',time()));
			$startmonthtime = strtotime(date('Y-m',$monthtime-2*24*3600));
			$params['onlinetime between']=array($startmonthtime,$monthtime);
		}elseif($daytype==5){
			
		}
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$return['list']=pdo_getslice('jy_merch_user',$params,array($pindex,$psize),$total,'','',$orderby);
	foreach($return['list'] as &$item){
		$params=array('merchid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']);
		$params1=$params;
		$item['jifen']=pdo_getsum('jy_liangoods_sendlog',$params1,'goodsprice');
		$params3=$params;
		$item['tonum']=pdo_count('jy_liangoods_sendlog',$params3,'id');
	}
	exi($return);
}
if($_RQ['op']=='getorderlist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$return['params']=array();
	//创建时间
	if($_RQ['tstart'] && $_RQ['tend']){
		$params['createtime between']=array($_RQ['tstart'],$_RQ['tend']);
	}else{
		$daytype=intval($_RQ['daytype']);
		if($daytype==0){
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['createtime >']=$daytime;
		}elseif($daytype==1){
			$yesdaytime = mktime(0,0,0,date('m'),date('d')-1,date('Y'));
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$params['createtime between']=array($yesdaytime,$daytime);
		}elseif($daytype=2){
			$day7time = mktime(0,0,0,date('m'),date('d')-7,date('Y'));
			$params['createtime >']=$day7time;
		}elseif($daytype==3){
			$monthtime = strtotime(date('Y-m',time()));
			$params['createtime >']=$monthtime;
		}elseif($daytype==4){
			$monthtime=strtotime(date('Y-m',time()));
			$startmonthtime = strtotime(date('Y-m',$monthtime-2*24*3600));
			$params['createtime between']=array($startmonthtime,$monthtime);
		}elseif($daytype==5){
			
		}
	}
	$list=array();
	$params0=$params;
	$list[0]=array(
		'title'=>'总配送额(元)',
		'num'=>pdo_getsum('jy_liangoods_sendlog',$params0,'goodsprice')?:0.00,
	);
	$params1=array('uniacid'=>$_SESSION['uniacid']);
	$list[1]=array(
		'title'=>'总商户(个)',
		'num'=>pdo_count('jy_merch_user',$params1,'id')?:0.00,
	);
	$params2=$params;
	$params2['sendtype']=1;
	$list[2]=array(
		'title'=>'总配送(单)',
		'num'=>pdo_count('jy_liangoods_sendlog',$params2,'id'),
	);
	$params3=$params;
	$params3['sendtype >=']=2;
	$list[3]=array(
		'title'=>'门店自提(单)',
		'num'=>pdo_count('jy_liangoods_sendlog',$params3,'id'),
	);
	$params4=$params;
	$params4['ispay']=1;
	$orders=pdo_getall('jy_weishop_order',$params4,array('id','price','dispatchprice'));
	$orderfee=0;
	$dispatchprice=0;
	$costprice=0;
	foreach($orders as $item){
		$orderfee +=$item['price'];
		$dispatchprice +=$item['dispatchprice'];
		$order_goods=pdo_getall('jy_weishop_order_goods',$params4,array('id','goodsid','total'));
		foreach($order_goods as $gv){
			$gvcostprice = pdo_getcolumn('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$gv['goodsid']),'costprice');
			$costprice +=$gvcostprice*$gv['total'];
		}
	}
	$fee=$orderfee-$costprice-$dispatchprice;
	$fee=intval($fee*100)/100;
	$list[4]=array(
		'title'=>'总盈利(元)',
		'num'=>$fee?:0.00,
	);
	$return['list']=$list;
	exi($return);
}